<template>
	<view>
		<web-view :src="src">
		</web-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				src: '',
				userInfo: {},
				remark: {}
			}
		},
		onLoad(options) {
			console.log(options.vt);
			this.userInfo = uni.getStorageSync('userInfo')
			let successUrl = encodeURIComponent(
				`https: //hzq.yoojet.com/#/pass/facePassLoading`
				// `https://mashangqian.yoojet.com/#/pages/signFor/signFor?Id=${uni.getStorageSync('Id')}&isType=true`
			)
			let errorUrl = encodeURIComponent(
				// `https://mashangqian.yoojet.com/#/?Id=${uni.getStorageSync('Id')}`
				`http://msq.yoojet.com/error`
			)
			this.src =
				`https://h5-faceverify.baidu.com/face/print/?token=${options.vk}&successUrl=${successUrl}&failedUrl=${errorUrl}`

			this.at = options.ak
			this.vt = options.vk
		},
		mounted() {
			window.addEventListener('message', (e) => {
				alert(e)
				if (e.data) {
					alert(e.data)
					if (e.data == '1') {
						setTimeout(() => {
							uni.reLaunch({
								url: '/pages/index/index?Id=' + uni.getStorageSync('Id')
							});
						}, 1000)
					} else {
						setTimeout(() => {
							uni.redirectTo({
								url: `/pages/signFor/signFor?Id=${uni.getStorageSync('Id')}&isType=true`
							})
						}, 1000)
					}
				}

			})

		},
		methods: {
			bindload(e) {
				alert(e)
				console.log(e, '加载');
				if (e.detail.src == `https: //hzq.yoojet.com/#/pass/facePassLoading`) {

					setTimeout(() => {
						uni.redirectTo({
							url: `/pages/signFor/signFor?Id=${uni.getStorageSync('Id')}&isType=true`
						})
					}, 1000)
					// uni.request({
					// 	url: "https://aip.baidubce.com/rpc/2.0/brain/solution/faceprint/result/detail?access_token=" +
					// 		this.at,
					// 	method: 'POST',
					// 	data: {
					// 		verify_token: this.vt
					// 	}
					// }).then(result => {
					// 	let [err, res] = result;
					// 	console.log(res.data);
					// 	if (res.data.success) {
					// 		this.certification(
					// 			res.data.result.idcard_confirm.idcard_number,
					// 			res.data.result.idcard_confirm.name,
					// 			JSON.stringify(res.data),
					// 			this.userInfo.UserPhone
					// 		);
					// 	} else {
					// 		uni.showToast({
					// 			title: '验证失败',
					// 			icon: 'none'
					// 		})
					// 		setTimeout(() => {
					// 			uni.reLaunch({
					// 				url: '/pages/index/index?Id=' + uni.getStorageSync('Id')
					// 			});
					// 		}, 1000)
					// 	}
					// })
				} else {
					setTimeout(() => {
						uni.reLaunch({
							url: '/pages/index/index?Id=' + uni.getStorageSync('Id')
						});
					}, 1000)
				}
			},
			binderror(e) {
				console.log(e)
			},
			bindMessage(e) {
				//如果通过消息机制，可以在这里处理数据，和进行页面跳转逻辑
				console.log('接收到的消息：' + JSON.stringify(e.detail.data));
			},
			// 保存认证记录
			certification(idNumber, name, remark, phone) {
				uni.request({
					url: this.$veriUrl + '/auth/VeriRecord',
					method: 'POST',
					data: {
						phone,
						name,
						idNumber,
						state: true,
						VeriType: 1,
						remark
					}
				}).then(result => {
					let [err, res] = result;
					if (res.data.code == 200) {
						uni.showToast({
							title: '验证成功',
							icon: 'none'
						})
						setTimeout(() => {
							uni.redirectTo({
								url: `/pages/signFor/signFor?Id=${uni.getStorageSync('Id')}&isType=true`
							})
						}, 1000)
					} else {
						uni.showToast({
							title: '验证失败',
							icon: 'none'
						})
						setTimeout(() => {
							uni.reLaunch({
								url: '/pages/index/index?Id=' + uni.getStorageSync('Id')
							});
						}, 1000)
					}
				})
			},
		}
	}
</script>

<style>

</style>